

<?php
    include ('styleadmin/admintop.php');
    include ('styleadmin/adminleft.php');
?> 

<div class ="adcontent">
<!-- TinyMCE -->
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->



<?php
// liệt kê tin tức
 $truycap = $_GET['truycap'];
    if($truycap =='lietketin'){
    $tintuc = "SELECT * FROM tintuc ORDER BY id DESC";
    $qrtintuc = mysql_query($tintuc) or die("kết nối bảng tin tức không thành công".mysql_error());
    $num = mysql_num_rows($qrtintuc);
    if($num > 0){
    echo "<form method ='post' action ='' id ='form_checkbox' name ='form_checkbox' onsubmit ='return check_checkbox();'>";
    echo "<div class ='divcontent'>";
        echo "<div class ='tieudedm'> Danh sách tin tức</div>";
    
        echo "<table>";
        echo "<th>Tiêu đề</th><th>Ngày đăng</th><th>Tình trạng</th><th><input type ='checkbox' id ='checkall' name ='checkall' value ='check_all'  onclick =\"selectReverse('form_checkbox','checkbox');\"/></th>";
        while($row = mysql_fetch_array($qrtintuc)){
            $matintuc = $row['id'];
            $tieude = $row['tieude'];
            $ngaydang = $row['ngay_post'];
            $hienthi = $row['hien_thi'];
            if($hienthi == 0){
                 $hienthi =  " <a href=\"#\" ><span id='hienthi_".$matintuc."'><img  onclick =\"khonghienthi('".$matintuc."')\" src ='images/icon-32-publish_01.png' title=\"Hiển thị\"  /></span></a>";
            }else{
                 $hienthi = " <a href=\"#\" ><span id='hienthi_".$matintuc."'><img onclick =\"hienthi('".$matintuc."')\" src ='images/icon-32-publish_02.png' title=\"Không hiển thị\" /></span></a>"; 
            }
            
            echo "<tr><td style ='width: 70%;'><a href = 'acp_tintuc.php?tintucid=".$matintuc."' title ='Xem chi tiết'>".$tieude."</a></td><td style ='width: 15%;'>".$ngaydang."</td><td  style ='text-align:center; width: 10%;'>".$hienthi."</td><td  style ='text-align:center; border-right: 0; '><input type ='checkbox' id ='checkbox_' name ='check[]' value ='".$matintuc."'/></td></tr>";             
        
            }
        echo "</table>";
        echo "<div class = 'divsubmit'><input class ='submittin save' type='submit' name ='xoatintuc'  value ='Xóa'/></div>";
    echo "</div>";
    echo "</form>";
    }else{
           echo "<div class ='tieudedm'> Danh sách tin tức chưa có </div>";
    }
 
 }
 
 // xóa tin tức
 if(isset($_POST['xoatintuc']) && isset($_POST['check'])){
    $arrid = $_POST['check'];
    $count = count($arrid);
    for($i= 0; $i < $count; $i++){
            $idtin = $arrid[$i];
            $sldelete = "DELETE FROM tintuc WHERE id =".$idtin."";
            $qrdelete = mysql_query($sldelete) or die("không thực hiện được xóa tin".mysql_error());
    
    }
 }
 
 // hiển thị chi tiết tin tức
 if(isset($_GET['tintucid'])){
     echo "<div class ='divcontent'>";
        echo "<div class ='bgtieude'> chi tiết tin tức</div>";
        $idtin = $_GET['tintucid'];
        $sqltt = "SELECT * FROM tintuc WHERE id =".$idtin;
        $qrtt = mysql_query($sqltt) or die("lỗi hiển thị chi tiết tin tức".mysql_error());
        $httin = mysql_fetch_array($qrtt);
        $tdt = $httin['tieude'];
        $ndt = $httin['noidung'];
        echo "<form action ='acp_tintuc.php?idsua=".$idtin."' method ='post' name ='formsuatin' onsubmit ='return check_valid();'>";
            echo "<div class='tdtin'>Tiêu đề :</div>";
            echo "<input class ='tieudetin' type ='text' id ='tieudetin' name ='tieudetin' value='".$tdt."'/>";
            echo "<div class ='noidungtin'>Nội dung :</div>";
            echo "<textarea class='ndtin' rows='15' cols='80' name='noidung' id ='noidung' value ='".$ndt."'>".$ndt." </textarea>";
            echo "<input class ='submitsuatin save' type ='submit' name ='suatin' id ='suatin' value ='Sửa'/>";
        echo "</form>";
     echo "</div>";
 }

// Sửa tin tức
if(isset($_POST['suatin'])){
    $idsua = $_GET['idsua'];
    $tdsua = $_POST['tieudetin'];
    $ndsua = $_POST['noidung'];
    $udtin = "UPDATE tintuc SET tieude = '".$tdsua."',noidung ='".$ndsua."' WHERE id =".$idsua."";
    $qrudtin = mysql_query($udtin) or die ("không update được tin".mysql_error());
    if($qrudtin){
        echo "<script> window.location ='acp_tintuc.php?truycap=lietketin'</script>";
    }else{
        echo "<script> window.location ='acp_tintuc.php?tintucid=".$idsua."'</script>";
    }
    
}
 // thêm tin tức mới
 
 $themtin = $_GET['addtt'];
 if($themtin =='themtintuc'){
   echo "<div class ='divcontent'>";
     echo "<div class ='bgtieude'> Thêm tin mới</div>";
     echo "<form action ='acp_tintuc.php?tt=them' method ='post' name ='formthemtin' onsubmit ='return check_valid();'>";
            echo "<div class='tdtin'>Tiêu đề :</div>";
            echo "<input class ='tieudetin' type ='text' id ='tieudetin' name ='tieudetin' value=''/>";
            echo "<div class ='noidungtin'>Nội dung :</div>";
            echo "<textarea class='ndtin' rows='15' cols='80' name='noidung' id ='noidung' value =''> </textarea>";
            echo "<input class ='submitsuatin save' type ='submit' name ='themtin' id ='themtin' value ='Thêm'/>";
        echo "</form>";
     
   echo "</div>";
 }
 if(isset($_POST['themtin'])){
    $date = date('d:m:Y');
  $them =  $_GET['tt'];
  if($them == 'them'){
    $tieudetin = $_POST['tieudetin'];
    $ndtin = $_POST['noidung'];
    $themtt = "INSERT INTO tintuc(tieude,noidung,ngay_post) VALUE('".$tieudetin."','".$ndtin."','".$date."')";
    $qrthemtin = mysql_query($themtt) or die ("không thêm được tin".mysql_error());
    if($qrthemtin){
        echo "<script> window.location='acp_tintuc.php?truycap=lietketin'</script>";
    }else{
          echo "<script> window.location='acp_tintuc.php?addtt=themtintuc'</script>";
    }
  }
 }
?>

</div>
    
    
 <?php   
    include ('styleadmin/adminfooter.php');
?>